package com.hspjava.StringBuilder;

public class StringBuilderVsStringBuffer {
    public static void main(String[] args) {
        long startTime = 0;
        long endTime = 0;



        StringBuffer s01 = new StringBuffer("");
        startTime = System.currentTimeMillis();
        for (int i = 0; i < 800000; i++) {
            s01.append(String.valueOf(i));
        }
        endTime = System.currentTimeMillis();
        System.out.println("StringBuffer的执行时间为:" + (endTime - startTime));


        StringBuilder s02 = new StringBuilder("");
        startTime = System.currentTimeMillis();
        for (int i = 0; i < 800000; i++) {
            s02.append(String.valueOf(i));
        }
        endTime = System.currentTimeMillis();
        System.out.println("StringBuilder的执行时间为:" + (endTime - startTime));



        String s = "";
        startTime = System.currentTimeMillis();
        for (int i = 0; i < 800000; i++) {
            s =  s + String.valueOf(i);
        }
        endTime = System.currentTimeMillis();
        System.out.println("String的执行时间为:" + (endTime - startTime));
    }
}
